1 00:00:00,170 --> 00:00:02,720 Now let's actually buy a lot. 2 00:00:02,750 --> 00:00:05,690 So let's look at our lots collection. 3 00:00:05,690 --> 00:00:07,520 And we currently have one lot. 4 00:00:07,730 --> 00:00:11,930 I'm going to go to my sign On the sign I have the buy prompt. 5 00:00:11,960 --> 00:00:15,920 We have to change a few values for action text. 6 00:00:15,950 --> 00:00:26,510 Let's call this buy property and then we want it to we want to have the whole duration more than zero 7 00:00:26,510 --> 00:00:27,110 seconds. 8 00:00:27,140 --> 00:00:33,410 Because if they change their mind, we want to give them a chance to release the hold button. 9 00:00:33,740 --> 00:00:34,460 There we go. 10 00:00:34,460 --> 00:00:38,360 Now, when you walk up, you'll get a prompt that'll say buy property. 11 00:00:38,390 --> 00:00:41,930 You have to hold it for three seconds before the sale to come through. 12 00:00:41,960 --> 00:00:46,300 Let's go up to our buy script right underneath the player lot. 13 00:00:46,310 --> 00:00:48,230 Open up the buy script. 14 00:00:48,800 --> 00:00:50,720 GEtrillionID of the print statement. 15 00:00:50,750 --> 00:00:56,330 We're going to need some variables, so I'm going to do one for the lot model lot model. 16 00:00:56,330 --> 00:00:57,530 That's the player lot. 17 00:00:57,560 --> 00:00:59,720 So it's just going to be script dot parent. 18 00:01:00,500 --> 00:01:07,850 I'm going to get a variable for this sign part right here because I'm going to want the buy prompt and 19 00:01:07,850 --> 00:01:09,680 I'm going to want that text label. 20 00:01:09,680 --> 00:01:12,910 So the sign is a good one to make a variable for. 21 00:01:12,920 --> 00:01:20,300 We'll do lot model and then for sale sign sign, that'll get us a lot closer to it. 22 00:01:20,300 --> 00:01:27,920 Then when I do my prompt I'll do sign and I got a buy prompt there. 23 00:01:29,120 --> 00:01:36,470 We're also going to need our property manager, so let's do Prop MGR. 24 00:01:36,500 --> 00:01:44,870 We're going to require that and that's a game server script Service Property Manager. 25 00:01:44,900 --> 00:01:46,010 There we go. 26 00:01:47,480 --> 00:01:49,000 Make a space in there. 27 00:01:49,010 --> 00:01:51,590 Oh, let's get a price. 28 00:01:51,800 --> 00:01:53,090 That's on the lot. 29 00:01:53,120 --> 00:01:56,450 Model price. 30 00:01:56,450 --> 00:01:58,250 And we need the owner. 31 00:01:58,280 --> 00:01:58,610 Oops. 32 00:01:58,610 --> 00:02:02,330 Owner lot, model owner. 33 00:02:02,630 --> 00:02:10,010 Now, when the player walks up, clicks the proximity prompt, he's going to trigger a prompt event. 34 00:02:10,010 --> 00:02:15,110 So we're going to get the prompt and the event is named triggered. 35 00:02:15,110 --> 00:02:20,000 So when it's triggered, we will connect to a function. 36 00:02:20,000 --> 00:02:24,110 The player who triggered the prompt will get passed into the function. 37 00:02:24,500 --> 00:02:38,660 Let's check to see if the player leader stats points dot value is greater than or equal to the price 38 00:02:38,660 --> 00:02:40,850 dot value of the lot. 39 00:02:40,880 --> 00:02:45,770 If it is, then we're going to do another check. 40 00:02:45,770 --> 00:02:55,130 We're going to check if not, prop manager is player lot owner. 41 00:02:55,130 --> 00:02:58,100 So right now we can only buy one lot. 42 00:02:58,190 --> 00:03:02,030 So we're checking to see if he's a lot owner pass in the player. 43 00:03:02,060 --> 00:03:04,070 That's going to be a true or false. 44 00:03:05,000 --> 00:03:09,230 Let me just adjust this explorer and properties so we have a little more room. 45 00:03:09,230 --> 00:03:14,060 So we get here, we have enough points and we don't already own a lot or the player doesn't already 46 00:03:14,060 --> 00:03:14,810 own a lot. 47 00:03:14,840 --> 00:03:24,350 We are going to subtract from the player's leader stats the number of points for the property. 48 00:03:24,350 --> 00:03:31,400 So we'll do a negative equals which will subtract the number of points using price dot value. 49 00:03:32,180 --> 00:03:34,850 Then we got to talk to our data manager, right? 50 00:03:34,850 --> 00:03:36,440 And that's our property manager. 51 00:03:36,470 --> 00:03:42,140 Property manager talks to the data store and we are going to add item to player's inventory. 52 00:03:42,140 --> 00:03:43,970 We have not finished that function though. 53 00:03:43,970 --> 00:03:48,000 We got to go back there and we have to add one line of code to make that work. 54 00:03:48,000 --> 00:03:49,830 We are going to pass in the player. 55 00:03:49,830 --> 00:03:52,020 We're going to pass in a key value. 56 00:03:52,050 --> 00:03:58,410 The key will be has lot and the value will be true. 57 00:03:59,100 --> 00:04:01,230 Oh, didn't quite make it. 58 00:04:03,050 --> 00:04:03,860 There we go. 59 00:04:05,450 --> 00:04:06,710 And what else? 60 00:04:06,740 --> 00:04:11,930 We need to change the owner tag. 61 00:04:12,110 --> 00:04:18,500 We have owner dot value, and that's going to be the player that owns the lot. 62 00:04:18,530 --> 00:04:20,720 Let me just go ahead and move that up. 63 00:04:21,080 --> 00:04:23,360 We're going to need the sign changed. 64 00:04:23,580 --> 00:04:24,620 I can't say for sale. 65 00:04:24,620 --> 00:04:25,370 Somebody owns it. 66 00:04:25,370 --> 00:04:30,470 So we'll say sign surface DUI, text label. 67 00:04:31,040 --> 00:04:34,010 Change the text to the player name player, dot name. 68 00:04:34,790 --> 00:04:39,020 And then let's turn the prompt off so that nobody can nobody thinks they can buy it because we already 69 00:04:39,020 --> 00:04:39,650 own it. 70 00:04:39,950 --> 00:04:44,990 So we'll say prompt dot enabled equals false. 71 00:04:45,570 --> 00:04:45,860 All right. 72 00:04:45,860 --> 00:04:47,870 So that's buying the property. 73 00:04:47,870 --> 00:04:51,440 Let's go over to add item to players inventory. 74 00:04:51,440 --> 00:04:56,390 I am going to right click go to declaration. 75 00:04:56,840 --> 00:05:05,520 We're in the property manager and here is the ADD item to players inventory down here we want to add. 76 00:05:07,050 --> 00:05:17,310 To the property table for the player, a key that equals our value. 77 00:05:17,430 --> 00:05:17,790 Right. 78 00:05:17,790 --> 00:05:20,870 So this is has a lot and that's going to be true. 79 00:05:20,880 --> 00:05:22,890 Then it's going to be in the property table. 80 00:05:23,550 --> 00:05:31,670 Now let's go back to our buy script and we have to account for leaving the game. 81 00:05:31,680 --> 00:05:38,100 I'm going to free up the property right here in the buy script, so I'll just do a game. 82 00:05:38,100 --> 00:05:49,650 Dot players, player service dot player removing connect to an anonymous function player gets passed 83 00:05:49,650 --> 00:05:50,280 in. 84 00:05:50,280 --> 00:05:56,580 We're going to check to see if the player that's leaving is actually the owner of this lot. 85 00:05:57,990 --> 00:06:04,830 If they are, we need to grab these three lines of code. 86 00:06:06,960 --> 00:06:08,070 And set it back. 87 00:06:08,070 --> 00:06:13,620 We have to free our lot, so we're going to free it by making that no, no property owner. 88 00:06:13,620 --> 00:06:16,950 And then this one we can say for sale again. 89 00:06:17,550 --> 00:06:19,050 For sale. 90 00:06:19,050 --> 00:06:20,550 I know that's using a string literal. 91 00:06:20,550 --> 00:06:21,750 That's not that good. 92 00:06:21,750 --> 00:06:26,520 And down here, prompt enabled is now true. 93 00:06:26,940 --> 00:06:29,730 Take a look at these three lines of code. 94 00:06:29,730 --> 00:06:31,980 Notice there's a pattern here. 95 00:06:31,980 --> 00:06:38,370 So whenever we're removing a player or we're making a purchase and also when we enter the game, if 96 00:06:38,370 --> 00:06:42,630 we own property, we have to change this, this and this. 97 00:06:42,690 --> 00:06:47,220 That is ripe for its own function in the property manager up here. 98 00:06:47,220 --> 00:06:49,410 We still we do it when we buy it, right? 99 00:06:49,440 --> 00:06:57,180 We assign the owner, we change the text in the sign and we enable we turn the prompt off. 100 00:06:57,180 --> 00:07:01,380 We disable the prompt if we go to our property manager, right? 101 00:07:01,440 --> 00:07:02,700 It's in server script service. 102 00:07:02,700 --> 00:07:04,530 If you lost it, I have it open. 103 00:07:04,740 --> 00:07:08,130 If I go down to equip player, look at that. 104 00:07:08,130 --> 00:07:09,990 I forgot the prompt. 105 00:07:09,990 --> 00:07:12,420 So I have my owner being assigned. 106 00:07:12,450 --> 00:07:13,200 That's good. 107 00:07:13,200 --> 00:07:15,360 The sign text is being changed. 108 00:07:15,360 --> 00:07:16,380 That's good. 109 00:07:16,380 --> 00:07:23,730 We need to disable the prompt because we're assigning the property to the player. 110 00:07:23,730 --> 00:07:25,440 So do V. 111 00:07:25,950 --> 00:07:31,650 We got the for sale sign for sale sign. 112 00:07:31,650 --> 00:07:34,770 So on the sign I forget. 113 00:07:36,290 --> 00:07:37,550 By prompt. 114 00:07:37,610 --> 00:07:43,070 I know that's all smooshed there, but I remember it now by prompt. 115 00:07:43,070 --> 00:07:48,890 And then that has a property called enabled and we're going to set that to false because we assign the 116 00:07:48,890 --> 00:07:50,750 property to somebody. 117 00:07:50,960 --> 00:07:54,440 We don't want people trying to buy it with the prompt popping up. 118 00:07:54,830 --> 00:07:55,210 All right. 119 00:07:55,220 --> 00:07:58,040 The next video, I'm going to do some print statements. 120 00:07:58,040 --> 00:08:01,310 We're going to do some testing and see if this works.